package mapevents;

import enumm.GROUND;
import gameengine.map.Field;
import gameengine.map.Map;
import gameengine.map.unit.Unit;

public abstract class AbstractMapEvent {
    public enum MAPEVENTTYPE {
        SELECT, DESELECT, MOVE, ATTACK, FIRERANGE, BUILDING
    }

    public static final AbstractMapEvent getMapEvent(final int xClick, final int yClick, final boolean leftClick, final Map map, final int party) {
        final Field field = map.getField(xClick, yClick);
        final Unit unit = field.getUnit();

        AbstractMapEvent currentEvent;

        if (leftClick) {
            if (unit == null || unit.getParty() != party) {
                if (field.getGround() == GROUND.BUILDING) {
                    currentEvent = new BuildingEvent(xClick, yClick);
                } else {
                    currentEvent = new MapDeSelection(xClick, yClick, unit);
                }
            } else {
                currentEvent = new MapSelection(xClick, yClick, unit);
            }
        } else {
            if (unit == null || unit.getParty() != party) {
                if (field.getGround() == GROUND.BUILDING) {
                    currentEvent = new BuildingEvent(xClick, yClick);
                } else {
                    currentEvent = new MapDeSelection(xClick, yClick, unit);
                }
            } else {
                currentEvent = new MapFireRangeSelection(xClick, yClick, unit);
            }
        }

        return currentEvent;
    }

    public abstract AbstractMapEvent newMapEvent(final int xClick, final int yClick, final boolean leftClick, final Map map, final int party);

    public abstract MAPEVENTTYPE getType();

    public abstract int getXStart();

    public abstract int getYStart();

    public abstract int getXTarget();

    public abstract int getYTarget();

    public abstract Unit getUnit();

    public abstract Unit getAttacker();
}
